<template>
  <div v-show="token">
    已登录{{ token }}
    <el-button type="primary" @click="logout">退出登录</el-button>
  </div>
  <div>
    首页
  </div>
  
</template>

<script>
import { ref, computed } from 'vue'
import { useStore } from 'vuex'
import { useRouter } from 'vue-router'
import Store from '@/store'

export default {
  setup() {
    const name = ref('')
    const router = useRouter()
    const store = useStore()
    const token = computed(() => {return store.state.user.token})

    const logout = async () => {
      await Store.dispatch('user/logout')
      router.push(`/login`)   
    }

    return {
      name,
      token,
      logout,
    }
  }
}
</script>

<style>

</style>